import json
import os
from enum import Enum
from dotenv import load_dotenv
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from ..database.db import get_db
from pydantic import BaseModel
from ..crud.user_crud import get_user_by_name
from ..utils.jwt_handler import get_username
from ..models.ai_models.examTest import QuestionGenerator

issues_router=APIRouter(prefix="/issue", tags=["出题"])

load_dotenv()
API_TOKEN=os.getenv("API_TOKEN")
@issues_router.get("/")
async def get_video():
    return {"message": "Hello World"}
class QuestionType(str, Enum):
    single_choice = "选择题"
    multiple_choice = "填空题"
    fill_in_the_blank = "简答题"
    judgment = "混合"

class IssuesParam(BaseModel):
    knowledge_point: str=...
    num_questions: int=...
    question_type: QuestionType=...
@issues_router.post("/")
async def create_issues(param: IssuesParam, db: Session = Depends(get_db),
                      username: str = Depends(get_username)):
    """
    # 参数说明
    - knowledge_point : 知识点
    - num_questions : 生成题的数量
    - question_type ： 题的类型（选择题、填空题、简答题、混合）
    """
    user=get_user_by_name(db,username)
    question_generator = QuestionGenerator()
    result = question_generator.run(
        knowledge_point=param.knowledge_point,
        num_questions=param.num_questions,
        question_type=param.question_type.value,
    )
    return {
        "code":200,
        "message":"success",
        "data":{
            "issues":result,

        }
    }